<template>
	<view class="mine">
		<view style="margin-top: 11rpx;">
			<view class="index_wrap" style="box-shadow: 0px 6px 20px 0px rgba(155, 155, 155, 0.5);">
				<swiper :indicator-dots="true" :autoplay="true" :interval="2000" :duration="1000" circular class='a'
					v-show="pictureFlag">
					<swiper-item v-for="(item,index) in swiperArray" :key='index' @click="toLink(index) ">
						<view class="swiper-item">
							<image mode="widthFix" class='swiper_img' :src="item.imgUrl" />
						</view>
						<view class="down__Owner_App " v-show="index == 1">
							<view class="down_cont_btn">
								<!-- <u-button shape="circle" type="warning"
									style="margin-top: 14px;height: 26px;">下载APP</u-button> -->
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
			<!-- --- 最新版本 -->
			<view class="list">
				<view class="list-detail">
					<view style="width: 235px;">最新版本
						<text style="font-size: 28rpx;color: #999999;margin-left: 30px;">
							{{new_edition_number}}
						</text>
					</view>
				</view>
				<view class="cont-all" @click='deletepop=true'>重新下载</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>
			<!-- -- 最新版本 -->
			<u-badge v-show='iconflag' count="新消息" :absolute="false" slot="right-icon"></u-badge>

			<view class="list" @click="navTo('/my/setUp/replacePhone')">
				<view class="list-detail">
					<view style="width: 187rpx;">更换手机号</view>
				</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>

			<view class="list" @click="navTo('/my/setUp/briefIntroduction')">
				<view class="list-detail">
					<view style="width: 187rpx;">修改简介</view>
				</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>

			<view class="list" @click="navTo('/my/setUp/agreement')">
				<view class="list-detail">
					<view style="width: 187rpx;">用户协议</view>
				</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>
			<view class="list" @click="navTo('/my/setUp/privacy')">
				<view class="list-detail">
					<view style="width: 187rpx;">隐私政策</view>
				</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>
			<view class="list" @click="navTo('/my/setUp/code')">
				<view class="list-detail">
					<view style="width: 187rpx;">平台QQ群</view>
					<view style="margin-left: 20px;">514489185</view>
				</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>
			
			<!-- <u-button shape="circle" type="warning"
				style="margin-top: 14px;height: 26px;">下载APP</u-button> -->
				
			<view class="list" @click="navTo('/my/setUp/cancellation')">
				<view class="list-detail">
					<view style="width: 187rpx;">注销账号</view>
				</view>
				<image src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/right.png" class="right"></image>
			</view>
		</view>

		<view v-if="phone" style="line-height: 50px;margin-top: 40rpx;padding-bottom: 20rpx;">
			<view @click="loginOut"
				style="align-items: center;width: 28%;margin: 0px auto;display: flex;border: 1px solid #DDDDDD;border-radius: 40px;line-height: 60rpx;">
				<view style="margin-top: 12rpx;margin-right: 7px; margin-left: 12px;">
					<image style="width: 16px;height: 16px;" src="https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/sing.png" mode=""></image>
				</view>
				<span style="color: #606266;font-weight: 700;">退出登录</span>
			</view>
		</view>
		<!-- 弹窗 -->
		<view class="modal" v-if="deletepop">
			<view class="modal-cont">
				<view class="modal-title">重新下载</view>
				<view style="display: flex;margin-top: 20px;text-indent: 2rem; padding: 0 30rpx;">
					<view><span>请先删除此app，重新到各大应用市场或助业网（www.515f.com）进行下载安装。</span></view>
				</view>

				<view class="modal-bottom">
					<view class="btn-cancel" @click="deletepop = false">取消</view>
					<view class="btn-sure" @click="deletepop=false">确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		pathToBase64,
		base64ToPath
	} from '../../utils/image-tool.js';
	// import UButton from './u-button/u-button.vue'
	// import apis from '@/apis/index';
	export default {
		data() {
			return {
				// 弹窗
				deletepop: false,
				pictureFlag: false,
				pictureFlag: true,
				iconflag: false,
				// company: uni.getStorageSync('orgDeta'),
				userInfo: uni.getStorageSync('rawData'),
				user_id: uni.getStorageSync('rawData').userId,
				pwdText: uni.getStorageSync('pwdText'),
				img: [], //上传完后的图片
				phone: null,
				name: null,
				edition_number: null, //当前版本
				new_edition_number: null, //最新版本
				swiperArray: [{
						index: 1,
						imgUrl: 'http://clhy-img.oss-cn-beijing.aliyuncs.com/venusImage/2021-12-15/1639571200709.png',
					},
					{
						index: 2,
						imgUrl: 'https://clhy-img.oss-cn-beijing.aliyuncs.com/ownerImage/zhuYeApp1.png',
					}
				],
			};
		},
		onShow() {
			console.log('mmmmmmmm')
			let _this = this;
			let rawData = uni.getStorageSync('rawData');
			console.log(rawData)
			if (rawData) {
				_this.pic = rawData.userHeadPortrait
				_this.name = rawData.userNickname
				_this.phone = rawData.userTel
				_this.login = true
			} else {
				_this.pic = null
				_this.name = null
				_this.phone = null
				_this.login = false
			}
			// #ifdef APP-PLUS
			var dangqianbb = "sadasd";
			var than = this;
			plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
				than.edition_number = wgtinfo.version;
				console.log(than.edition_number)
			})
			// #endif
			uni.request({
				url: 'https://www.515f.com/api/rest/v1/venusSysAppUpgradeService/getNewAppInfoByType',
				method: 'POST',
				data: {
					app_type: 2
				},
				success: res => {
					const response = res.data.data;
					this.new_edition_number = response.edition_number
					console.log("最新版本" + response.edition_number)
				}
			})
		},
		methods: {
			downBtn() {
				//应用宝链接
				// location.href='https://a.app.qq.com/o/simple.jsp?pkgname=uni.UNI21DD88C'
				//华为市场链接
				location.href =
					'https://appgallery.huawei.com/app/C104867875?sharePrepath=ag&locale=zh_CN&source=appshare&subsource=C104867875&shareTo=weixin&shareFrom=appmarket';
				//vivo链接
				//https://h5coml.vivo.com.cn/h5coml/appdetail_h5/browser_v2/index.html?appId=3319176&resource=301&source=2
			},
			//淘宝链接
			toLink(index) {
				if (index == 1) {
					uni.navigateTo({
						url: '/privateMsg/user/downApp'
					})
				} else {
					var link = 'https://m.tb.cn/h.Ue5wdsa'
					this.$request.api.getBookLink({}).then(res => {
						link = res.data.data.link
						// #ifdef H5
						window.open(
							link
						)
						// #endif
						// #ifdef APP-PLUS
						plus.runtime.openURL(
							link,
							function(res) {
								console.log(res);
							});
						// #endif
					})
				}
			},
			checkUpdate() {
				// #ifdef APP-PLUS
				plus.screen.lockOrientation('portrait-primary') //竖屏正方向锁定

				const updated = uni.getStorageSync('updated') // 尝试读取storage
				if (updated.completed === true) { // 如果上次刚更新过
					// 删除安装包及安装记录
					console.log('安装记录被删除，更新成功')
					uni.removeSavedFile({
						filePath: updated.packgePath,
						success: (res) => {
							uni.removeStorageSync('updated')
						}
					})
				} else if (updated.completed === false) {
					uni.removeStorageSync('updated')
					plus.runtime.install(updated.packgePath, {
						force: true
					})
					uni.setStorage({
						key: 'updated',
						data: {
							completed: true,
							packgePath: updated.packgePath
						},
						success: (res) => {
							console.log('成功安装上次的更新，应用需要重启才能继续完成')
						}
					})
					uni.showModal({
						title: '提示',
						content: '应用将重启以完成更新',
						showCancel: false,
						complete: () => {
							plus.runtime.restart()
						}
					})
				}
				// #endif

				setTimeout(() => {
					plus.navigator.closeSplashscreen();
				}, 3000);
				if (uni.getStorageSync("uuid")) {
					uni.switchTab({
						url: "/pages/index/index"
					});
				}
			},
			//上传图片
			uploadImg() {
				let that = this;
				uni.chooseImage({
					count: 1,
					success(res) {
						that.img.push(res.tempFilePaths[0]);
						//file转base64
						pathToBase64(res.tempFilePaths[0]).then(res => {
							that.$request.api
								.uploadImage({
									imageBase64: res
								})
								.then(data => {
									let userInfo = that.userInfo;
									userInfo.userHeadPortrait = data.data.data;
									uni.setStorageSync('rawData', userInfo)

									that.$request.api
										.updateImage({
											user_id: that.user_id,
											user_head_portrait: data.data
										}).then(res => {
												uni.showToast({
													title: '修改成功',
													duration: 2000,
													icon: 'none'
												});
											},
											err => {
												this.loading = true;
												uni.showToast({
													title: err.errorMessage,
													duration: 2000,
													icon: 'none'
												});
												return;
											}
										);
								});
						});
					}
				});
			},
			//跳转
			navTo(url) {
				uni.redirectTo({
					url: url
				})
			},
			loginOut() {
				let _this = this
				uni.clearStorage();
				this.phone = null;
				this.name = null;
				// 进入首页
				uni.clearStorageSync();
				uni.reLaunch({ //跳转页面
					url: "/pages/user/user"
				})
				uni.removeStorageSync('announcement')
			},
		}
	};
</script>

<style lang="scss">
	.index_wrap {
		width: 91vw;
		height: auto;
		margin: 10rpx auto;
		overflow: hidden;
	}

	.index_wrap .a .swiper_img {
		width: 100%;
		height: 150px;
		box-shadow: 0px 6px 20px 0px rgba(155, 155, 155, 0.5);
	}

	.index_wrap .message {
		width: calc(100vw - 60rpx);
		margin: auto;
		height: 90rpx;
		border-radius: 12rpx;
		background: #FEF6EB;
		overflow: hidden;
	}

	.index_wrap .message .message_icon {
		width: 32rpx;
		height: 32rpx;
		float: left;
		margin: 26rpx 0 0 26rpx;
		background-size: 100%;
	}

	.index_wrap .message .message_icon image {
		width: 100%;
	}

	.index_wrap .message .message_swiper {
		float: left;
		width: calc(100% - 80rpx);
		margin: auto;
		height: 32rpx;
		margin: 25rpx 0 30rpx 20rpx;
	}

	.down__Owner_App {
		width: 750rpx;
		height: 422rpx;
	}

	.down_cont_btn {
		position: absolute;
		width: 180rpx;
		height: 60rpx;
		top: 95px;
		left: 40rpx;
	}

	.mine {
		.list {
			padding: 0 40rpx 0 40rpx;
			background: #FFF;
			line-height: 100rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-weight: 500;
			color: #333333;
			font-size: 32rpx;
			border-bottom: 1rpx solid #EEEEEE;

			.cont-all {
				font-size: 28rpx;
				font-weight: 400;
				color: #999999;
				text-shadow: 0rpx 2rpx 0rpx #EEEEEE;
			}

			.list-detail {
				display: flex;
				align-items: center;

				.left {
					width: 48rpx;
					height: 48rpx;
					margin-right: 25rpx;
				}
			}

			.herder-logo {
				display: flex;
				align-items: center;

				.logo-image {
					width: 60rpx;
					height: 60rpx;
					background: #D8D8D8;
					border-radius: 30rpx;
					margin-right: 29rpx;
				}

				.right {
					width: 22rpx;
					height: 36rpx;
				}
			}

			.right {
				width: 22rpx;
				height: 36rpx;
			}
		}
	}

	.modal {
		position: fixed;
		top: 0%;
		left: 0%;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.8);
		z-index: 10;
	}

	.modal-cont {
		width: 610rpx;
		// min-height: 420rpx;
		background: #ffffff;
		box-shadow: 0rpx 6rpx 12rpx 0rpx rgba(0, 0, 0, 0.12);
		border-radius: 24rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.modal-icon {
		width: 80rpx;
		height: 80rpx;
		margin-top: 67rpx;
	}

	.modal-title {
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		color: #333333;
		line-height: 45rpx;
		margin-top: 22rpx;
		align-items: center;
		border-bottom: 1px solid #ddd;
		padding: 10px 20px 10px;
		text-align: center;
		width: 89%;
		margin: auto;
	}

	.modal-content {
		width: 443rpx;
		// height: 88rpx;
		font-size: 28rpx;
		text-align: center;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 44rpx;
		margin-top: 24rpx;
	}

	.text-area {
		margin-top: 24rpx;
		width: 520rpx;
		padding: 10rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		line-height: 44rpx;
		max-height: 105rpx;
		border: 1rpx solid #f0f0f0;
		border-radius: 8rpx;
	}

	.modal-bottom {
		width: 100%;
		height: 84rpx;
		border-top: 1rpx solid #e6e9ed;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 50rpx;
	}

	.btn-cancel {
		width: 50%;
		height: 84rpx;
		text-align: center;
		line-height: 84rpx;
		border-right: 1rpx solid #d8d8d8;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		box-sizing: border-box;
	}

	.btn-sure {
		width: 50%;
		height: 84rpx;
		text-align: center;
		line-height: 84rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #578ef0;
	}
</style>